package com.taotao.controller;

import com.taotao.common.pojo.EasyUIDataGridResult;
import com.taotao.common.pojo.EasyUITreeNode;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.content.service.IContentCategoryService;
import com.taotao.content.service.IContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author zhangxiaolin@zhonhajt.com
 * @Title: 内容分类controller
 * @Package com.taotao.portal.controller
 * @Description:
 * @date 2018/10/18 21:15
 */
@Controller
@RequestMapping("/content/category")
public class ContentCategoryController {

    @Autowired
    private IContentCategoryService contentCategoryService;

    @Autowired
    private IContentService contentService;

    /**
     * 查询内容分类列表
     * @param parentId
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public List<EasyUITreeNode> getContentCategory(@RequestParam(value = "id", defaultValue = "0") Long parentId) {
        List<EasyUITreeNode> treeNodeList = contentCategoryService.getContentCategoryList(parentId);
        return treeNodeList;
    }

    /**
     * 新增内容分类
     * @param parentId
     * @param name
     * @return
     */
    @RequestMapping("/create")
    @ResponseBody
    public TaotaoResult getContentCategory(@RequestParam(value = "parentId", defaultValue = "0") Long parentId, String name) {
        TaotaoResult result = contentCategoryService.addContentCategory(parentId, name);
        return result;
    }

    @RequestMapping("/update")
    @ResponseBody
    public TaotaoResult updateContentCategory(@RequestParam(value = "id", defaultValue = "0") Long id, String name) {
        TaotaoResult result = contentCategoryService.updateContentCategory(id, name);
        return result;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public TaotaoResult deleteContentCategory(@RequestParam(value = "id", defaultValue = "0") Long id) {
        TaotaoResult result = contentCategoryService.deleteContentCategory(id);
        return result;
    }
}
